<?php

use Biz\model\brandActivity\BlindBoxActivity as mBlindBoxActivity;
use Biz\model\brandActivity\BlindBoxLottery as mBlindBoxLottery;
use Doraemon\service\User;
use Doraemon\tools\ImgUrl;

/**
 * 分享图片奖品
 */
class ShareImgAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_NOTHING;

    public function main()
    {
        $lotteryId = $this->getRequest()->getPost('lottery_id', 0);
        $uid = !empty($this->uid) ? $this->uid : $this->getRequest()->getPost('uid', 0);
        if (!$lotteryId || !$uid) {
            throw new \Exception('参数错误');
        }
        $lotteryInfo = mBlindBoxLottery::getByWhere(['id' => $lotteryId]);
        $img = '';
        if ($lotteryInfo['prize_type'] == mBlindBoxActivity::PRIZE_TYPE_LIMIT_CARD) {
            $img = $lotteryInfo['prize_value'] ? ImgUrl::getUrl(ImgUrl::APPTYPE_OP, $lotteryInfo['prize_value'], ImgUrl::IMAGE_SIZE_OP_ORI) : '';
        }
        $userInfo = User::getBasicUserInfo($uid);
        $info = [
            'img' => $img,
            'user_info' => $userInfo,
        ];
        $this->setSuccess($info);
    }
}